package com.system.animal.controller;

import com.system.animal.entity.Dog;
import com.system.animal.service.DogService;
import com.system.animal.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dog")
public class DogController {
    //当晚就做完了.问老师说这个不用扫描配置中就自动配置了,就修改了一下,删除了config包
    //在service层,删除了impl包,按照我们上课的样式进行了修改.尽量改成了我们实训时的写法
    //添加了R工具类,进行提醒提示
    //添加了改和删的功能
    //数据库名为test,表格为dog,
    @Autowired
    private DogService dogService;

    @GetMapping("/list")
    public R<List<Dog>> list() {
        System.out.println("Controller层调用:: "+"查询所有狗狗");
        List<Dog> list = dogService.findAllDog();
        return R.success("查询成功",list);
    }
    @PutMapping("/add")
    public R<Object> add(@RequestBody Dog dog) {
        System.out.println("Controller层调用:: "+"添加狗狗");
        int result = dogService.addDog(dog);
        if (result == 1){
            return R.success("添加成功");
        }
        return R.success("添加失败");
    }
    @DeleteMapping("/del/{id}")
    public R<Object> del(@PathVariable int id){
        System.out.println("Controller层调用:: "+"删除狗狗");
        int result = dogService.delDog(id);
        if (result == 1){
            return R.success("删除成功");
        }
        return R.success("删除失败");
    }
    @PutMapping("/update")
    public R<Object> update(@RequestBody Dog dog){
        System.out.println("Controller层调用:: "+"更新狗狗");
        int result = dogService.updateDog(dog);
        if (result == 1){
            return R.success("更新成功");
        }
        return R.success("更新失败");
    }
}
